//
//  DownLoadOpration.h
//  nsurlsession
//
//  Created by lk on 16/4/11.
//  Copyright © 2016年 lk. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Reachability.h"
#import "CoreStatus.h"

typedef void(^DownloadProgressBlock)(CGFloat progress, long long totalMBRead, long long totalMBExpectedToRead);
typedef void(^PuseDownBlock)();
typedef void(^DownloadSuccessBlock)(NSString *sucDownPath,NSString *SucDownName);

typedef void(^DownloadFailureBlock)(NSError *error,NSString *errorDownPath,NSString *errorDowName);
typedef void(^PhoneLastCount)(NSString *lastCount);
typedef void(^NetBreakBlock)();
typedef void(^PauseFinishBlock)();
typedef void(^RestartFinishBlock)();
typedef void(^DeletFinishBlock)();
typedef void(^AllstopComplete)();
typedef void(^AllstartComplete)();
typedef void(^ExitSuccess)();
typedef void(^AllDeleteSuccess)();

@protocol DownLoadOprationDelegate <NSObject>
-(void)mangerDidPause;
@end
@interface DownLoadOpration : NSObject<NSURLSessionDelegate,NSURLSessionTaskDelegate>
{
    NSURLSession *sessional;
    BOOL  isDownLoading;
    
}
@property(nonatomic,assign)float progress;
//下载任务
@property(nonatomic,strong)NSURLSessionDownloadTask *task;
//多用户时唯一标示符(建议使用user_id)
@property(nonatomic,copy)NSString *userflag;
//存储空间名（例：图片：picture）
@property(nonatomic,copy)NSString *storagePath;
//链接名
@property(nonatomic,copy)NSString *downpath;
//本地存储文件名 （建议使用下载文件的唯一标示符）abc.mp3 agc.mp4(点不能少)
@property(nonatomic,copy)NSString *localName;
//切换前一个文件名,在切换前 lastName == localName
@property(nonatomic,copy)NSString *lastName;
//链接数组
@property (nonatomic,strong)NSMutableArray *downPathMuArr;
//失败／暂停的维护链接数组
@property (nonatomic,strong)NSMutableArray *stopDownpathArr;
//存储下载文件名数组
@property (nonatomic,strong)NSMutableArray *storagePathMuArr;
//失败／暂停的维护文件名数组
@property (nonatomic,strong)NSMutableArray *stopStorageArr;
//重新入时需要加载的信息
@property (nonatomic,strong)NSMutableDictionary *messagessDic;
@property(nonatomic,strong)DownloadProgressBlock downloadProgressBlock;
@property(nonatomic,strong)DownloadSuccessBlock downloadSuccessBlock;
@property(nonatomic,strong)DownloadFailureBlock downloadFailureBlock;
@property(nonatomic,strong)NetBreakBlock netBeakBlock;
@property(nonatomic,strong)PauseFinishBlock pausefinishBolock;
@property(nonatomic,strong)RestartFinishBlock restartfinishBlock;
@property(nonatomic,strong)DeletFinishBlock deletfinishBlock;
@property (nonatomic,strong)AllstartComplete allstartcomplete;
@property (nonatomic,strong)AllstopComplete allstopcompelete;
@property (nonatomic,strong)ExitSuccess exitsuccess;
@property (nonatomic,strong)AllDeleteSuccess alldeletsuccess;
@property (nonatomic,strong)PhoneLastCount lastCount;
@property(nonatomic,weak) id <DownLoadOprationDelegate> delegate;
//开始下载 第一个参数传链接
-(void)downloadFileWith:(NSMutableArray *)urlArray;
+(instancetype)getInstance;
//暂停当前下载的某一个链接
-(void)pauseTaskWithLocalPath:(NSString *)localPath;
//继续下载
-(void)resumeTask;
//全部暂停
-(void)pauseDownload;
//判断某一个链接的下载状态
-(BOOL)isNowDownForDownPath;
//全部删除
-(void)deleteAll;
-(BOOL)isNowDownForDownPath:(NSString *)localPath;
//重新开始
-(void)restartTaskWithLocalPath:(NSString *)localPath;
//全部暂停
-(void)allStop;
//全部开始
-(void)allStart;
//删除多个任务
-(void)deletDownloadTaskwith:(NSMutableArray *)urlArr WithNameArr:(NSMutableArray *)nameArr WithUserFlag:(NSString *)userflag;

-(void)exitTheprogram;

-(void)gainLastCount;

@end
